package com.zbkj.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.zbkj.common.model.Warehouse;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.WarehouseSearchRequest;
import com.zbkj.service.dao.WarehouseDao;
import com.zbkj.service.service.WarehouseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author keNan
 * @description WarehouseServiceImpl 接口实现
 * @date 2025-06-05
 */
@Service
public class WarehouseServiceImpl extends ServiceImpl<WarehouseDao, Warehouse> implements WarehouseService {

    @Resource
    private WarehouseDao dao;


    /**
     * 列表
     *
     * @param request          请求参数
     * @param pageParamRequest 分页类参数
     * @return List<Warehouse>
     * @author keNan
     * @since 2025-06-05
     */
    @Override
    public List<Warehouse> getList(WarehouseSearchRequest request, PageParamRequest pageParamRequest) {
        PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return dao.selectListBySearch(request);
    }


    /**
     * 新增仓库
     *
     * @param warehouse
     * @return
     */
    @Override
    public Boolean addWarehouse(Warehouse warehouse) {
        warehouse.setCreateTime(new Date());
        if (1 == warehouse.getIsDefault()) {
            LambdaUpdateWrapper<Warehouse> luw = new LambdaUpdateWrapper<>();
            luw.set(Warehouse::getIsDefault, 0);
            luw.eq(Warehouse::getIsDefault, 1);
            update(luw);
        }
        return save(warehouse);
    }

}

